package logic

import (
	"context"
	"math/rand"
	"real-check/models/cache"
	"time"

	"real-check/checkrpc/checkrpc"
	"real-check/checkrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SmsLogic {
	return &SmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SmsLogic) Sms(in *checkrpc.SmsRequest) (*checkrpc.SmsResponse, error) {
	// todo: add your logic here and delete this line
	code := rand.Intn(9000) + 1000
	cache.Rdb.Set(l.ctx, "sms"+in.Moble, code, time.Minute*2)
	return &checkrpc.SmsResponse{}, nil
}
